#pragma once
#include <string>
#include <cassert>
class BinTriNode
{
public:
	BinTriNode(void):
	  Parent(NULL),LeftChild(NULL),RightChild(NULL),
	  LeftNeighbor(NULL),RightNeighbor(NULL),BaseNeighbor(NULL),
	  Code(),Number(0){}
					 
	~BinTriNode(void);

	 BinTriNode * GetParent() const { return Parent; }
	 void SetParent(BinTriNode * val) { Parent = val; }
	 BinTriNode * GetLeftChild() const { return LeftChild; }
	 void SetLeftChild(BinTriNode * val) { LeftChild = val; }
	 BinTriNode * GetRightChild() const { return RightChild; }
	 void SetRightChild(BinTriNode * val) { RightChild = val; }
	 BinTriNode * GetLeftNeighbor() const { return LeftNeighbor; }
	 void SetLeftNeighbor(BinTriNode * val) { LeftNeighbor = val; }
	 BinTriNode * GetBaseNeighbor() const { return BaseNeighbor; }
	 void SetBaseNeighbor(BinTriNode * val) { BaseNeighbor = val; }
	 BinTriNode * GetRightNeighbor() const { return RightNeighbor; }
	 void SetRightNeighbor(BinTriNode * val) { RightNeighbor = val; }
	 unsigned int GetNumber() const { return Number; }
	 void SetNumber(unsigned int val) { Number = val; }

	std::string GetCode() const { return Code; }
	void SetCode(std::string val) { Code = val; }
	void Reset(){
		Parent=LeftChild=RightChild=LeftNeighbor=RightNeighbor=BaseNeighbor=NULL;
		Code="";
		Number=0;
	}
 	bool IsInvaild(){return Number==0;}
	void SetVertex0(float x,float y){x0=x,y0=y;}
	void SetVertex1(float x,float y){x1=x,y1=y;}
	void SetVertex2(float x,float y){x2=x,y2=y;}

	void GetVertex0(float& x,float& y){x=x0,y=y0;}
	void GetVertex1(float& x,float& y){x=x1,y=y1;}
	void GetVertex2(float& x,float& y){x=x2,y=y2;}

	void GetCoordinate(float & x,float &y,float &i,float &j,float &a,float &b){
		x=x0,y=y0,i=x1,j=y1,a=x2,b=y2;
	}

	void GetVertexAsLeftChild(){
		assert(Parent!=NULL);
		float x,y,a,b;
		Parent->GetVertex0(x,y);
		SetVertex1(x,y);
		Parent->GetVertex1(a,b);
		SetVertex2(a,b);
		Parent->GetVertex2(x,y);
		SetVertex0((x+a)*0.5,(y+b)*0.5);
	}

	void GetVertexAsRightChild(){
		assert(Parent!=NULL);
		float x,y,a,b;
		Parent->GetVertex0(x,y);
		SetVertex2(x,y);
		Parent->GetVertex2(a,b);
		SetVertex1(a,b);
		Parent->GetVertex1(x,y);
		SetVertex0((x+a)*0.5,(y+b)*0.5);
	}




private:
	BinTriNode * Parent;
	BinTriNode * LeftChild;
	BinTriNode * RightChild;
	BinTriNode * LeftNeighbor;
	BinTriNode * RightNeighbor;
	BinTriNode * BaseNeighbor;
	
	std::string Code;
	unsigned int Number;
	float x0,y0,x1,y1,x2,y2;

};



